/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.univcasa.managing.impl;

import com.univcasa.db.model.CompteEtudiant;
import com.univcasa.db.model.ComptePersonnel;
import com.univcasa.managing.ComptesStudentsManager;
import com.univcasa.managing.LdapDBManager;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;


/**
 *
 * @author issam
 */
public class testLDAPManager {

    public static void main(String[] args){

        //testListUidsLdap("ens*9") ;
        //testAjoutListALdap();
        //testListUidsLdap("*") ;
        //testListStudentsLdap();
        //testListStudentsErroredLdap();
        //testUpdateStdLdap();
        //testUpdateErroredStdLdap();
        //testListSomPersLdap();
        //testgetPersBySom("1434131");
        HashMap criteres =  new HashMap();
        criteres.put("nom", "KHAWLA");
        testSearchStdLdap( criteres);


    }
    public static void testgetPersBySom(String som){
        LdapDBManager managerLdap = new LdapDBManagerImpl();
        ComptePersonnel pers = managerLdap.recupererPersBySom(som);
        System.out.println("Pers" + pers.getEtab() + pers.getNom() + pers.getFonction() +pers.getPassword());
    }

    public static void testListSomPersLdap(){

        LdapDBManager managerLdap = new LdapDBManagerImpl();
        List lista = managerLdap.recupererListesomPers();

        for(Iterator itr=lista.iterator(); itr.hasNext();){
            String som = (String) itr.next();
            System.out.println("entry " + som);
        }
    }

    public static void testListUidsLdap(String uidPattern){
        LdapDBManager managerLdap = new LdapDBManagerImpl();
        List lista = managerLdap.recupererListeUids(uidPattern);

        for(Iterator itr=lista.iterator(); itr.hasNext();){
            String uid = (String) itr.next();
            System.out.println("uid " + uid );
        }
    }

    public static void testListStudentsLdap(){

        LdapDBManager managerLdap = new LdapDBManagerImpl();
        List lista = managerLdap.recupererListeStudentsLdap();

        

        for(Iterator itr=lista.iterator(); itr.hasNext();){
            CompteEtudiant etud = (CompteEtudiant) itr.next();
            System.out.println("std " + etud.getApogee()+ " " + etud.getNom() );
        }
    }

     public static void testListStudentsErroredLdap(){

        LdapDBManager managerLdap = new LdapDBManagerImpl();
        List lista = managerLdap.recupererEtudiantErrored();



        for(Iterator itr=lista.iterator(); itr.hasNext();){
            CompteEtudiant etud = (CompteEtudiant) itr.next();
            System.out.println("std " + etud.getApogee()+ " " + etud.getNom() );
        }
    }

    public static void testListEntriesLdap(){

        LdapDBManager managerLdap = new LdapDBManagerImpl();
        List lista = managerLdap.recupererListeApogeeEtudiants();

        for(Iterator itr=lista.iterator(); itr.hasNext();){
            String apogee = (String) itr.next();
            System.out.println("entry " + apogee);
        }
    }

    public static void testAjoutListALdap(){

        /*
        ComptesStudentsManager manager = new ComptesStudentsManagerImpl();
        LdapDBManager managerLdap = new LdapDBManagerImpl();

        List lista = manager.getAllComptesStudents();

        for(Iterator itr=lista.iterator(); itr.hasNext();){

            CompteEtudiant etudiant = (CompteEtudiant) itr.next();
            System.out.println("etudiant " + etudiant.getApogee() +" " + etudiant.getNom() + " " + etudiant.getPrenom());

            managerLdap.ajoutCompteEtudiantLdap( etudiant );
        }
         **/
    }

    public static void testUpdateErroredStdLdap(){
        LdapDBManager managerLdap = new LdapDBManagerImpl();
        List lista = managerLdap.recupererEtudiantErrored();
        System.out.println("ERRORED comptes");
        for(Iterator itr=lista.iterator(); itr.hasNext();){
            CompteEtudiant etudiant = (CompteEtudiant) itr.next();
            System.out.println("etudiant " + etudiant );
            managerLdap.majCompteEtudiantLdap(etudiant);

        }
    }

    public static void testUpdateStdLdap(){
        
        LdapDBManager managerLdap = new LdapDBManagerImpl();
        CompteEtudiant std = managerLdap.recupererEtudiantByApogee("123456");
        System.out.println("Std" + std );
        std.setNom("makhloufi");
        managerLdap.majCompteEtudiantLdap(std);
        System.out.println("Std maj" + std );        
    }

    public static void testSearchStdLdap(HashMap criteres){

        LdapDBManager managerLdap = new LdapDBManagerImpl();
        List lista = managerLdap.searchStdsByCriteres(criteres);
        for(Iterator itr=lista.iterator(); itr.hasNext();){
            CompteEtudiant etud = (CompteEtudiant) itr.next();
            System.out.println("std " + etud.getApogee()+ " " + etud.getNom() + " " + etud.getPassword() );
        }
    }
}